package com.choosefine.it.manager.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.base.dto.PageDTO;
import com.choosefine.it.common.def.CommonConstant;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.model.CustomRestTemplate;
import com.choosefine.it.common.utils.DateUtils;
import com.choosefine.it.common.utils.StringUtils;
import com.choosefine.it.company.model.CompanyPublishproject;
import com.choosefine.it.company.model.vo.CompanyPublishProjectDetailVO;
import com.choosefine.it.company.model.vo.CompanyPublishProjectInfoVO;
import com.choosefine.it.company.model.vo.CompanyPublishProjectVO;
import com.choosefine.it.company.service.CompanyPublishprojectService;
import com.choosefine.it.manager.model.ManagerProjectCollection;
import com.choosefine.it.manager.service.ManagerSelectProjectInfoService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 项目 经理找项目
 * 
 * @author chenjian
 * @date 2016-11-30 下午5:04:31
 */
@RestController
@RequestMapping("/managerSelectProject")
@Api(value = "项目经理找项目及收藏项目", description = "俞鑫")
public class ManagerSelectprojectinfoController extends BaseController {
	@Autowired
	private ManagerSelectProjectInfoService managerSelectProjectInfoService;
	@Autowired
	private CompanyPublishprojectService companyPublishprojectService;
	@Autowired
	CustomRestTemplate restTemplate;
	@Autowired
	ObjectMapper jsonObjectMapper;
	Logger logger = LoggerFactory.getLogger(ManagerSelectprojectinfoController.class);

	@ApiImplicitParams({
			@ApiImplicitParam(name = "projectTypeId", value = "工程类别id", required = false, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "areaCode", value = "省或市", required = false, dataType = "String", paramType = "query"),
			@ApiImplicitParam(name = "random",value = "工程类别名称/项目名称/建筑公司名称",required = false,dataType = "String",paramType = "query"),
			@ApiImplicitParam(name = "pageNum", value = "起始页", required = true, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "int", paramType = "query") })
	@RequestMapping(value = "/getProjectList", method = RequestMethod.GET)
	@ApiOperation(value = "项目经理找项目列表",response=CompanyPublishProjectVO.class)
	public String managerSelectproject(Integer projectTypeId, String areaCode,
			String random, Integer pageNum, Integer pageSize) {
		String result = null;
		Map map=new HashMap();
		map.put("projectTypeId",projectTypeId);
		map.put("areaCode",areaCode);
		map.put("random",random);
		PageDTO page = new PageDTO();
		page.setPageNum(pageNum);
		page.setPageSize(pageSize);
		Page<CompanyPublishProjectVO> list = managerSelectProjectInfoService.selectProjectList(map, page);
		result = responseSuccess(list);
		return result;
	}

/*yuxin3.8 update*/
	@ApiOperation(value = "项目经理查询项目的详情",notes="陈健",response=CompanyPublishproject.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "项目经理租户编号", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "发布的ID", required = true, dataType = "int", paramType = "path"),
			})

	@RequestMapping(value = "/getProjectInfoDetail/{userCode}/{uuid}/{publishId}", method = RequestMethod.GET)
	public String getTeamInfoDetail(@PathVariable String userCode,@PathVariable String uuid,@PathVariable Integer publishId)
			throws JsonProcessingException {
		String result = null;
		Map map=new HashMap();
		map.put("userCode",userCode);
		map.put("uuid",uuid);
		map.put("publishId",publishId);
		map.put("type",CommonConstant.MANAGER_COLLECT_COMPANY);//5：项目经理收藏建筑公司发布的找项目承包人
		CompanyPublishproject companyPublishproject=companyPublishprojectService.getDetails(map);
		result=responseSuccess(companyPublishproject);
		return result;
	}

	@ApiOperation(value = "项目经理收藏")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "项目经理的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "建筑公司发布该条信息的id", required = true, dataType = "int", paramType = "path")
			 })
	@RequestMapping(value = "/saveCollectProject/{userCode}/{uuid}/{publishId}", method = RequestMethod.POST)
	public String saveCollectProject(
			@PathVariable String userCode,
			@PathVariable String uuid,
			@PathVariable Integer publishId
			) {
		String result = null;
		Map map=new HashMap();
		map.put("userCode",userCode);
		map.put("uuid",uuid);
		map.put("publishId",publishId);
		map.put("type",CommonConstant.MANAGER_COLLECT_COMPANY);//5：项目经理收藏建筑公司发布的找项目承包人
		map.put("ctime",System.currentTimeMillis());
		int num=managerSelectProjectInfoService.managerCollectionProject(map);
		if(0==num){
			result=responseFail();
		}else {
			result=responseSuccess(num);
		}
		return result;
	}
	
	@ApiOperation("项目经理取消收藏")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "项目经理的userCode", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid", value = "uuid", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "publishId", value = "建筑公司发布该条信息的id", required = true, dataType = "int", paramType = "path")
	})
	@RequestMapping(value="/cancelCollectProject/{userCode}/{uuid}/{publishId}",method=RequestMethod.PUT)
	public String cancelCollectProject(@PathVariable String userCode,
									   @PathVariable String uuid,
									   @PathVariable Integer publishId){
		String result = null;
		Map map=new HashMap();
		map.put("userCode",userCode);
		map.put("uuid",uuid);
		map.put("publishId",publishId);
		map.put("type",CommonConstant.MANAGER_COLLECT_COMPANY);//5：项目经理收藏建筑公司发布的找项目承包人
		map.put("utime",System.currentTimeMillis());
		int num=managerSelectProjectInfoService.cancelCollectionProject(map);
		if(0==num){
			result=responseFail();
		}else {
			result=responseSuccess(num);
		}
		return result;
	}
	
	@ApiOperation(value = "项目经理查询收藏的项目列表",response = CompanyPublishProjectVO.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userCode", value = "用户编号", required = true, dataType = "String", paramType = "path"),
			@ApiImplicitParam(name = "uuid",value = "uuid",required = true,dataType = "String",paramType = "path"),
			@ApiImplicitParam(name = "pageNum", value = "起始页", required = true, dataType = "int", paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "一页显示的行数", required = true, dataType = "int", paramType = "query") })
	@RequestMapping(value="/findCollectProjectList/{userCode}/{uuid}",method=RequestMethod.GET)
	public String findCollectProjectList(@PathVariable String userCode,@PathVariable String uuid,
										 @RequestParam Integer pageNum,@RequestParam Integer pageSize){
			String result = null;
			Map<String, Object> params = new HashMap<>();
			params.put("userCode", userCode);
			params.put("uuid",uuid);
			params.put("type",CommonConstant.MANAGER_COLLECT_COMPANY);//5：项目经理收藏建筑公司发布的找项目承包人
			PageDTO pageDTO = new PageDTO();
			pageDTO.setPageNum(pageNum);
			pageDTO.setPageSize(pageSize);
			Page<CompanyPublishProjectVO> list = managerSelectProjectInfoService.findCollectProjectList(pageDTO,params);
			result = responseSuccess(list);
			return result;
	}
}
